package com.gzy.cbrsystem.insomnia;

import java.sql.Timestamp;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * InsomniaBasicInfo entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.gzy.cbrsystem.insomnia.InsomniaBasicInfo
 * @author MyEclipse Persistence Tools
 */

public class InsomniaBasicInfoDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory
			.getLog(InsomniaBasicInfoDAO.class);
	// property constants
	public static final String PATIENT_NAME = "patientName";
	public static final String DOCTOR_NAME = "doctorName";
	public static final String SEX = "sex";
	public static final String NATIONALITY = "nationality";
	public static final String PATIENT_FROM = "patientFrom";
	public static final String CARE_TYPE = "careType";
	public static final String CAREER = "career";
	public static final String CAREER_TYPE = "careerType";
	public static final String MARRIAGE = "marriage";
	public static final String EDUCATION = "education";
	public static final String LIVING_SITE = "livingSite";
	public static final String CIRCUMSTANCES = "circumstances";
	public static final String DECEASE = "decease";
	public static final String DIAGNOSIS = "diagnosis";
	public static final String ISSOLVED = "issolved";

	protected void initDao() {
		// do nothing
	}

	public void save(InsomniaBasicInfo transientInstance) {
		log.debug("saving InsomniaBasicInfo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(InsomniaBasicInfo persistentInstance) {
		log.debug("deleting InsomniaBasicInfo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public InsomniaBasicInfo findById(java.lang.String id) {
		log.debug("getting InsomniaBasicInfo instance with id: " + id);
		try {
			InsomniaBasicInfo instance = (InsomniaBasicInfo) getHibernateTemplate()
					.get("com.gzy.cbrsystem.insomnia.InsomniaBasicInfo", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(InsomniaBasicInfo instance) {
		log.debug("finding InsomniaBasicInfo instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding InsomniaBasicInfo instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from InsomniaBasicInfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByPatientName(Object patientName) {
		return findByProperty(PATIENT_NAME, patientName);
	}

	public List findByDoctorName(Object doctorName) {
		return findByProperty(DOCTOR_NAME, doctorName);
	}

	public List findBySex(Object sex) {
		return findByProperty(SEX, sex);
	}

	public List findByNationality(Object nationality) {
		return findByProperty(NATIONALITY, nationality);
	}

	public List findByPatientFrom(Object patientFrom) {
		return findByProperty(PATIENT_FROM, patientFrom);
	}

	public List findByCareType(Object careType) {
		return findByProperty(CARE_TYPE, careType);
	}

	public List findByCareer(Object career) {
		return findByProperty(CAREER, career);
	}

	public List findByCareerType(Object careerType) {
		return findByProperty(CAREER_TYPE, careerType);
	}

	public List findByMarriage(Object marriage) {
		return findByProperty(MARRIAGE, marriage);
	}

	public List findByEducation(Object education) {
		return findByProperty(EDUCATION, education);
	}

	public List findByLivingSite(Object livingSite) {
		return findByProperty(LIVING_SITE, livingSite);
	}

	public List findByCircumstances(Object circumstances) {
		return findByProperty(CIRCUMSTANCES, circumstances);
	}

	public List findByDecease(Object decease) {
		return findByProperty(DECEASE, decease);
	}

	public List findByDiagnosis(Object diagnosis) {
		return findByProperty(DIAGNOSIS, diagnosis);
	}

	public List findByIssolved(Object issolved) {
		return findByProperty(ISSOLVED, issolved);
	}

	public List findAll() {
		log.debug("finding all InsomniaBasicInfo instances");
		try {
			String queryString = "from InsomniaBasicInfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public InsomniaBasicInfo merge(InsomniaBasicInfo detachedInstance) {
		log.debug("merging InsomniaBasicInfo instance");
		try {
			InsomniaBasicInfo result = (InsomniaBasicInfo) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(InsomniaBasicInfo instance) {
		log.debug("attaching dirty InsomniaBasicInfo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(InsomniaBasicInfo instance) {
		log.debug("attaching clean InsomniaBasicInfo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static InsomniaBasicInfoDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (InsomniaBasicInfoDAO) ctx.getBean("InsomniaBasicInfoDAO");
	}
}